<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="livcos.org/ns/doc"
  xmlns:tst="livcos.org/ns/pm/test"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="doc tst xs">

  <xsl:template match="tst:case">
    <div id="{@id}" class="test_case">
      <h2>
        <xsl:if test="not(tst:test[last()]/@passed = '1')">
        	<xsl:attribute name="class">test_failed</xsl:attribute>
        </xsl:if>
      	<xsl:value-of select="tst:title" />
      </h2>
      <xsl:apply-templates select="doc:*" />
      <xsl:if test="tst:test">
        <table cellspacing="0">
          <thead>
            <tr>
              <th>Time</th>
              <th>Tester</th>
              <th>Env.</th>
              <th>Comments</th>
            </tr>
          </thead>
          <tbody>
            <xsl:apply-templates select="tst:test">
              <xsl:sort select="@time" order="descending"/>
            </xsl:apply-templates>
          </tbody>
        </table>
      </xsl:if>
    </div>
  </xsl:template>

  <xsl:template match="tst:test">
    <tr id="{@id}">
      <xsl:if test="not(@passed = '1')"><xsl:attribute name="class">test_failed</xsl:attribute></xsl:if>
      <td>
        <xsl:value-of
          select="format-dateTime(xs:dateTime(@time), '[D01].[M01].[Y01] [H01]:[m01]:[s01]')"/>
      </td>
      <td align="center"><xsl:value-of select="@actor"/></td>
      <td>
        <xsl:value-of select="tst:environment"/>
      	<xsl:if test="normalize-space(tst:environment) = ''">&#160;</xsl:if>
      </td>
      <td>
      	<xsl:value-of select="tst:comment"/>
      	<xsl:if test="normalize-space(tst:comment) = ''">&#160;</xsl:if>
      </td>
    </tr>
  </xsl:template>
  
</xsl:stylesheet>
